package com.gmt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author John.zhang
 * @version Id: GmGlobalFilter, v 1.0 2020/11/20 17:33 ZhiYong Exp $
 * 全局过滤
 */

@Component
public class GmGlobalFilter implements GlobalFilter, Ordered {

    Logger logger = LoggerFactory.getLogger(GmGlobalFilter.class);

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        logger.info("[Pre]GmGlobalFilter.apply");
        return chain.filter(exchange).then(Mono.fromRunnable(()->{
            logger.info("[Post]GmGlobalFilter.apply");
        }));
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
